package com.shanghaionstar.carmanage.adapter;

import android.content.Context;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.onstar.cn.framework.mvp.base.core.BaseFragment;
import com.shanghaionstar.R;
import com.shanghaionstar.home.HomeFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 6335yz on 2016/7/24.
 */
public class SimpleFragmentPagerAdapter extends FragmentPagerAdapter {

    private String[] titles;
    private Context context;

    public SimpleFragmentPagerAdapter(FragmentManager fm, Context context) {
        super(fm);
        this.context = context;
        titles = context.getResources().getStringArray(R.array.car_tab_name);
    }

    @Override
    public BaseFragment getItem(int position) {
        return new HomeFragment();
    }

    @Override
    public int getCount() {
        return titles.length;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        //第一次的代码
        //return tabTitles[position];
        //第二次的代码
        /**
         Drawable image = context.getResources().getDrawable(imageResId[position]);
         image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
         SpannableString sb = new SpannableString(" " + tabTitles[position]);
         ImageSpan imageSpan = new ImageSpan(image, ImageSpan.ALIGN_BOTTOM);
         sb.setSpan(imageSpan, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
         return sb;*/
        return titles[position];
    }

    private TextView tb_btn;
    private List<TextView> btns = new ArrayList<>();

    public View getTabView(int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.car_manage_tab_item, null);
        tb_btn = (TextView) view.findViewById(R.id.tb_btn);
//        tb_btn.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT, 1.0f));
        tb_btn.setText(titles[position]);
        tb_btn.setTextColor(context.getResources().getColor(R.color.color_1762cb));
        tb_btn.setBackgroundResource(R.drawable.common_btn_cancel_bg_click);
        btns.add(tb_btn);
        return view;
    }

    public void changeBtnCheckStyle(int position) {
        if (position >= titles.length || position < 0) return;
        TextView changeTextBtn = btns.get(position);
        changeTextBtn.setTextColor(context.getResources().getColor(R.color.white));
        changeTextBtn.setBackgroundResource(R.drawable.common_btn_bg_click);
    }

    public void changeBtnUNCheckStyle(int position) {
        if (position >= titles.length || position < 0) return;
        TextView changeTextBtn = btns.get(position);
        changeTextBtn.setTextColor(context.getResources().getColor(R.color.color_1762cb));
        changeTextBtn.setBackgroundResource(R.drawable.common_btn_cancel_bg_click);
    }



}
